﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace FSM
{
    public class ListNode:Condition
    {
        protected List<Condition> list = new List<Condition>();
        protected int index = 0;
        public void Adds(params Condition[] param)
        {
            if(param.Length > 0)
            {
                foreach(var item in param)
                {
                    Add(item);
                }
            }
        }
        public override void Init(params object[] param)
        {
            foreach(var item in param)
            {
                var it = item as Condition;
                if(it)
                {
                    Add(it);
                }
            }
        }
        public void Add(Condition value)
        {
            list.Add(value);
        }
        protected override void OnEnter()
        {
            base.OnEnter();
            index = 0;
            foreach (var item in list)
            {
                item.Enter();
            }
        }
        protected override void OnLeave()
        {
            foreach(var item in list)
            {
                item.Leave();
            }
        }
        protected override bool OnUpdate()
        {
            var b = base.OnUpdate();
            //list.ForEach(item => item.Update());
            foreach(var it in list)
            {
                it.Update();
            }
            return true;
        }
    }

}
